
//
//  U9Share.m
//  U9WatchGame
//
//  Created by uuu9 on 2017/7/12.
//  Copyright © 2017年 UUU9. All rights reserved.
//

#import "U9Share.h"
#import <UMShare/UMShare.h>
#import <UMShare/UMSocialManager.h>

@implementation U9Share

+ (void)shareWithImageUrl:(NSString *)imageUrl andDesc:(NSString *)desc andTitle:(NSString *)title andShareURL:(NSString *)url andShareType:(NSInteger)type andBlock:(void (^)(bool b))block{

    //创建分享消息对象
    UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject];
    //创建网页内容对象
    UMShareWebpageObject *shareObject = [UMShareWebpageObject shareObjectWithTitle:title descr:desc thumImage:imageUrl];
    //设置网页地址
    shareObject.webpageUrl = url;
    //分享消息对象设置分享内容对象
    messageObject.shareObject = shareObject;
    
    //调用分享接口
    [[UMSocialManager defaultManager] shareToPlatform:type messageObject:messageObject currentViewController:nil completion:^(id data, NSError *error) {
        if (error) {
            NSLog(@"************Share fail with error %@*********",error);
            block(NO);
        }else{
            NSLog(@"response data is %@",data);
            block(YES);
        }
    }];
}


+ (void)shareWithImage:(UIImage *)image andDesc:(NSString *)desc andTitle:(NSString *)title andShareURL:(NSString *)url andShareType:(NSInteger)type andBlock:(void (^)(bool b))block{
    
    //创建分享消息对象
    UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject];
    //创建网页内容对象
    UMShareWebpageObject *shareObject = [UMShareWebpageObject shareObjectWithTitle:title descr:desc thumImage:image];
    //设置网页地址
    shareObject.webpageUrl = url;
    //分享消息对象设置分享内容对象
    messageObject.shareObject = shareObject;
    
    
    //调用分享接口
    [[UMSocialManager defaultManager] shareToPlatform:type messageObject:messageObject currentViewController:nil completion:^(id data, NSError *error) {
        if (error) {
            NSLog(@"************Share fail with error %@*********",error);
            block(NO);
        }else{
            NSLog(@"response data is %@",data);
            block(YES);
        }
    }];
}


@end
